<template>
	<el-form :model="formData" ref="formRef" :rules="formRules" label-width="12rem">
		<el-row type="flex" :gutter="10">
			<el-col :span="24">
				<el-form-item label="活动图片(750*500)" prop="img">
					<!-- <el-upload-image v-model="formData.img" :disabled="isdisabled" :limit="6"
						:title="title"></el-upload-image> -->
						 <el-upload-image v-model="formData.img" :limit="5" :title="title"></el-upload-image>
				</el-form-item>
			</el-col>
			<!-- <el-col :span="12">
				<el-form-item label="供应商名称" prop="nickname">
					<el-input v-model="formData.nickname" clearable placeholder="请输入供应商名称"></el-input>
				</el-form-item>
			</el-col> -->
			<el-col :span="12">
				<el-form-item label="活动组织管理员" prop="uid">
					<el-select v-model="formData.uid" size="mini" placeholder="请选择活动组织管理员" :disabled="isdisabled">
						<el-option v-for="item in memberData" :key="item.id" :label="item.name" :value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="组织管理员名称" prop="uid">
					<el-input v-model="formData.user_name" placeholder="请输入组织管理员名称"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="活动名称" prop="activity_name">
					<el-input :disabled="isdisabled" v-model="formData.activity_name" clearable
						placeholder="请输入活动名称"></el-input>
				</el-form-item>
			</el-col>
			<!-- <el-col :span="12">
				<el-form-item label="类型" prop="type">
					<el-select v-model="formData.type" size="mini" placeholder="请选择活动类型 " :disabled="isdisabled"
						@change="changetype">
						<el-option v-for="item in typelist" :key="item.id" :label="item.title" :value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
			</el-col> -->
			<!-- <el-col :span="12">
				<el-form-item label="社区" >
					<el-select v-model="formData.community_id" size="mini" placeholder="请选择社区" :disabled="isdisabled">
						<el-option v-for="item in comlist" :key="item.id" :label="item.name" :value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
			</el-col> -->
			<el-col :span="12">
				<el-form-item label="活动时间" prop="time">
					<el-date-picker :disabled="isdisabled" v-model="formData.time" value-format="timestamp"
						type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
					</el-date-picker>
				</el-form-item>
			</el-col>

			<el-col :span="12">
				<el-form-item label="报名数量" prop="sign_num">
					<el-input v-model="formData.sign_num" :disabled="isdisabled" clearable placeholder="请输入报名数量"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="报名金额" prop="sign_money">
					<el-input v-model="formData.sign_money" :disabled="isdisabled" clearable type="number"
						placeholder="请输入报名金额"></el-input>
				</el-form-item>
			</el-col>
			<!-- <el-col :span="12">
				<el-form-item label="核销送积分" prop="score">
					<el-input v-model="formData.score" clearable :disabled="isdisabled || $store.getters.isAdmin == false" type="number"
						placeholder="请输入获得积分"></el-input>
				</el-form-item>
			</el-col> -->
			<!-- 是否可使用积分抵扣 -->
			<!-- <el-col :span="12">
				<el-form-item label="是否可使用积分抵扣" prop="is_dk">
					<el-radio-group v-model="formData.is_dk" :disabled="!$store.getters.isAdmin">
						<el-radio :label="1">是</el-radio>
						<el-radio :label="0">否 </el-radio>
					</el-radio-group>
				</el-form-item>
			</el-col>
			<el-col :span="12" v-if="formData.type==1">
				<el-form-item label="志愿者是否报名赠送积分" prop="is_have_score">
					<el-radio-group v-model="formData.is_have_score" :disabled="!$store.getters.isAdmin">
						<el-radio :label="1">是</el-radio>
						<el-radio :label="0">否 </el-radio>
					</el-radio-group>
				</el-form-item>
			</el-col> -->
			<!-- <el-col :span="12" v-if="formData.is_points_gift == 1">
				<el-form-item label="报名送积分" prop="gift_score">
					<el-input-number v-model="formData.gift_score" :controls="false"  :disabled="$store.getters.isAdmin"></el-input-number>
				</el-form-item>
			</el-col> -->
			<!-- <el-col :span="12">
				<el-form-item label="联系电话" prop="number">
					<el-input v-model="formData.number" clearable :disabled="isdisabled" type="number"
						placeholder="请输入联系电话"></el-input>
				</el-form-item>
			</el-col> -->
			<el-col :span="12">
				<el-form-item label="排序" prop="sort">
					<el-input v-model="formData.sort" clearable :disabled="isdisabled" type="number"
						placeholder="请输入说明"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="详细地址" prop="address_info">
					<el-input v-model="formData.address_info" clearable :disabled="isdisabled"
						placeholder="请输入详细地址"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="24">
				<el-form-item label="地图" prop="location">
					<maps :location.sync="formData.location" :isdisabled="isdisabled"></maps>
				</el-form-item>
			</el-col>
			<el-col :span="24">
				<el-form-item prop="desc" label="详情">
					<div>
						<Editor height="700px" style="width:375px" v-model="formData.desc"
							:defaultConfig="editorConfig" :mode="mode" @onCreated="onCreated" :disabled="isdisabled" />
					</div>
				</el-form-item>
			</el-col>
		</el-row>
		<el-row type="flex" justify="center">
			<el-button type="primary" :disabled="isdisabled" icon="el-icon-check" @click="onConfirm">确认</el-button>
			<el-button type="default" icon="el-icon-close" @click="onCancel">取消</el-button>
		</el-row>
	</el-form>
</template>

<script>
import { imghttp, get, post, del } from '@/assets/js/http'
// import { Editor, Toolbar } from "@wangeditor/editor-for-vue";
import Editor from '@/components/editor.vue'
export default {
	name: "member-search",
	props: {
		formData: {
			type: Object,
			default: () => { }
		},
		isdisabled: {
			type: Boolean,
			default: false
		},
	},
	components: {
		"el-upload-image": () => import("@/components/el-upload-image.vue"),
		"maps": () => import("@/components/map/index.vue"),
		Editor,
		// Toolbar
	},
	mounted() {
		this.getcommuity()
		this.getMemberData()
	},
	data() {
		return {
			memberData: [],
			editor: null,
			toolbarConfig: {},
			editorConfig: {
				MENU_CONF: {
					uploadImage: {
						fieldName: "file",
						server: "/admin/ajax/upload",
						headers: {
							batoken: this.$store.state.token
						},
						/* eslint-disable-next-line */
						customInsert(res, insertFn) {
							insertFn(
								$store.getters.baseUrl + res.data.file.url
							);
						}
					}
				},
				uploadVideo: {
						fieldName: "file",
						server: "/admin/ajax/upload",
						headers: {
							batoken: this.$store.state.token,
						},
						/* eslint-disable-next-line */
						customInsert(res, insertFn) {
							insertFn($store.getters.baseUrl + res.data.file.url)
						},
					},
			},
			mode: "default",
			formRules: {
				img: [{
					required: true,
					message: '请上传',
					trigger: 'change'
				}],
				desc: [{ required: true, message: '请输入', trigger: 'change' },],
				location: [{ required: true, message: '请输入', trigger: 'change' },],
				activity_name: [{ required: true, message: '请输入', trigger: 'change' },],
				// type: [{ required: true, message: '请选择', trigger: 'change' },],
				uid: [{ required: true, message: '请选择', trigger: 'change' },],
				time: [{ required: true, message: '请选择', trigger: 'change' },],
				sign_num: [{ required: true, message: '请输入', trigger: 'change' },],
				sign_money: [{ required: true, message: '请输入', trigger: 'change' }],
				score: [{ required: true, message: '请输入', trigger: 'change' }],
				sort: [{ required: true, message: '请输入', trigger: 'change' }],
				// number: [{ required: true, message: '请输入', trigger: 'change' }],
				// community_id: [{ required: true, message: '请选择', trigger: 'change' },],
				address_info: [{ required: true, message: '请输入', trigger: 'change' }],
				// is_have_score:[{ required: true, message: '请选择', trigger: 'change' }],
				gift_score:[{ required: true, message: '请输入', trigger: 'change' }],
				// is_dk:[{ required: true, message: '请选择', trigger: 'change' }],
			},
			title: '请上传1.5:1比例的图片',
			typelist: [{ id: 1, title: '志愿者招募活动' }, { id: 2, title: '普通活动' }],//1志愿者招募活动2普通活动
			comlist: [],//社区列表
		};
	},
	beforeDestroy() {
		const editor = this.editor;
		if (editor == null) return;
		editor.destroy();
	},
	methods: {
		onCreated(editor) {
			this.editor = Object.seal(editor);
		},
		onConfirm() {
			console.log(this.formData.img)
			// return
			this.$refs.formRef.validate((valid) => {
				if (valid) {
					// if (this.formData.type == 1) {
					// 	this.formData.sign_money = 0
					// }
					this.formData.admin_id = this.$store.state.id
					// this.formData.time = [this.formData.time[0]/1000,this.formData.time[1]/1000]
					this.formData.start_time = this.formData.time[0] / 1000
					this.formData.end_time = this.formData.time[1] / 1000
					this.formData.latitude = this.formData.location.lat
					this.formData.longitude = this.formData.location.lng
					this.formData.type = 2
					
					// alert('submit!');
					console.log(this.formData, this.formData.desc)
					this.$emit("search", this.formData);
					this.$parent.$emit("update:visible", false);
					this.$refs.formRef.resetFields()
				} else {
					console.log('error submit!!');
					return false;
				}
			});
		},
		onCancel() {
			this.$parent.$emit("update:visible", false);
			this.$refs.formRef.resetFields();
		},
		async getcommuity() {
			await get({
				url: '/admin/project.Community/index',
				params: {
					...this.searchParam,
					...{
						server_type: this.$route.query.type ? 2 : 1,
						limit: 9999
						// search_time:this.searchParam.search_time.length?this.searchParam.search_time.join(' - '):''
					}
				}
			}).then(res => {
				this.comlist = res.list
			})
		},
		async getMemberData() {
			const data = await get({
				url: "/admin/user.RealmeritUser/index",
				loading: true,
				params: {
					// page: this.page,
					limit: 9999,
					is_verifier: 1,//是否核销员 0否 1是
					is_agent: 0,//0用户列表 1代理商列表
					// ...this.searchinfo,
					// ...{
					// 	search_time: this.searchinfo.search_time.length ? this.searchinfo.search_time.join(
					// 		' - ') : ''
					// }
				}
			});
			const list = data.list;
			this.total = data.total;
			this.memberData = list.list;
		},
		changetype(e) {
			console.log(e)
			if (e == 1) {
				this.formData.sign_money = 0
			}
		}
	}
};
</script>
<style src="@wangeditor/editor/dist/css/style.css"></style>
